package com.kuang.controller;


import com.alibaba.fastjson.JSON;
import com.kuang.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**体验fastjson用法
 * @author FHL
 */
@RestController
public class FastJsonDemo {
    @RequestMapping("/json4")
    public static String main(String[] args) {
        //创建对象
        User u1=new User(1,"吉鲁1",111);
        User u2=new User(2,"吉鲁2",111);
        User u3=new User(3,"吉鲁3",111);
        List<User> list=new ArrayList<User>();
        list.add(u1);
        list.add(u2);
        list.add(u3);
        System.out.println("java对象转换成json字符串");
        String s = JSON.toJSONString(list);
        System.out.println(s);
        return s;
    }
}
